'use strict';
app.service('postageService',['$http','$q','utilService',function($http,$q,utilService){
    var _this_=this;

    //查询区域
    this.findTemplate = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'postage/template',
            params:$scope.postageTemplateVO
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }

    //查询区域
    this.findArea = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'area'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }

    //添加单独模板
    _this_.add=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"postage/template",
            data:$scope.postageTemplateJson
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //添加单独模板
    _this_.edit=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"postage/template",
            data:$scope.postageTemplateJson,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }


    //查询单独模板
    this.findTemplateBO = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'postage/template/bo',
            params:$scope.postageTemplateVO
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }


    //删除模板
    _this_.del=function($scope,id){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"postage/template/del",
            data:{id:id},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }


}]);
